package com.movie.playvideos.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.movie.playvideos.R;
import com.movie.playvideos.model.Movie;

public class CustomMoviesAdapter extends ArrayAdapter<Movie>{

	private List<Movie> mListMovies;
	private Context mContext;
	
	public CustomMoviesAdapter(Context context, int resource,
			List<Movie> objects) {
		super(context, resource, objects);
		
		mListMovies = objects;
		mContext = context;
	}

	@Override
	public int getCount() {
		return mListMovies.size();
	}
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		
		if (convertView == null) {
			holder = new ViewHolder();
			LayoutInflater inflater = LayoutInflater.from(mContext);
			convertView = inflater.inflate(R.layout.each_clip_fragment, null);
			
			holder.urlMovie = (ImageView) convertView.findViewById(R.id.urlMovie);
			holder.titleMovie = (TextView) convertView.findViewById(R.id.titleMovie);
			holder.durationMovie = (TextView) convertView.findViewById(R.id.durationMovie);
					
			convertView.setTag(holder);
			
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		
		Movie item = mListMovies.get(position);
		holder.titleMovie.setText(item.getTitle());
//		holder.urlMovie
		holder.durationMovie.setText(item.getDuration());
		
		return convertView;
	}
	
	static class ViewHolder {
		ImageView urlMovie;
		TextView titleMovie;
		TextView durationMovie;
	}
}
